home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 311 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  45 lines

  1. Path: news.sni.de!news
  2. From: Josef Moellers <mollers.pad@sni.de>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Array Parameters
  5. Date: 4 Jan 1996 07:52:36 GMT
  6. Organization: Siemens Nixdorf Informationssysteme AG, Paderborn, Germany
  7. Message-ID: <4cg104$qmp@nervous.pdb.sni.de>
  8. References: <wayne.820650643@hawk> <4ce349$4j9@hacgate2.hac.com> <820701694snz@genesis.demon.co.uk>
  9. NNTP-Posting-Host: uranium.pdb.sni.de
  10. X-Newsreader: NN version 6.5.0 #2
  11.  
  12. In <820701694snz@genesis.demon.co.uk> Lawrence Kirby <fred@genesis.demon.co.uk> writes:
  13.  
  14. [ ... ]
  15.  
  16. >                            It is impossible
  17. >to specify an array as a function parameter since, as in the example above,
  18.  
  19. Well, if you MUST pass an array by value and not by reference, wrap it
  20. into a structure:
  21.  
  22. struct foo {
  23.     int array[100];
  24. };
  25. ...
  26. func(struct foo bar)
  27. {
  28.     ...
  29.     bar.array[23] = 25;
  30.     ...
  31. }
  32. ...
  33. struct foo foo_array;
  34. ...
  35. foo_array.array[23] = 7;
  36. func(foo_array);
  37. printf("%d\n", foo_array.array[23]);
  38. ...
  39.  
  40. will print "7", rather than "23".
  41.  
  42. Please note that this is very expensive at runtime.
  43. --
  44. Josef Moellers            mollers.pad@sni.de
  45.